package com.yoga.manager.app.impl;

import com.yoga.common.appexception.AppErrorCodeEnum;
import com.yoga.common.appexception.AppException;
import com.yoga.common.bo.PrivateVipBO;
import com.yoga.dao.dao.PrivateVipDao;
import com.yoga.dao.domain.PlainVipDO;
import com.yoga.dao.domain.PrivateVipDO;
import com.yoga.manager.app.AppPrivateVipManager;
import com.yoga.manager.beanUtil.PrivateVipBeanUtil;
import com.yoga.manager.uitl.DateStyle;
import com.yoga.manager.uitl.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by hdx on 2020/9/26.
 */
@Component
public class AppPrivateVipManagerImpl implements AppPrivateVipManager {
    Logger logger = LoggerFactory.getLogger(AppPrivateVipManagerImpl.class);

    @Resource
    private PrivateVipDao privateVipDao;

    @Override
    public PrivateVipBO getPrivateVipByUserId(Long yogaUserId) throws AppException {
        if (yogaUserId == null) {
            throw new AppException(AppErrorCodeEnum.YOGA_USER_ID_NULL);
        }
        PrivateVipDO privateVipDO = privateVipDao.findByYogaUserId(yogaUserId);
        if (privateVipDO == null) {
            throw new AppException(AppErrorCodeEnum.QUERY_PRIVATE_NULL);
        }
        PrivateVipBO privateVipBO = PrivateVipBeanUtil.privateVipDOToBO(privateVipDO);
        if (privateVipBO.getVipType() == 0) {
            privateVipBO.setVipStatus(0);
        } else if (privateVipBO.getVipType() == 1) {
            if (privateVipBO.getClassNum() > 0) {
                privateVipBO.setVipStatus(1);
            } else {
                privateVipBO.setVipStatus(0);
            }
        }

        return privateVipBO;
    }

    @Override
    public Boolean getIsPrivateVIP(Long yogaUserId) throws AppException {
        if (yogaUserId == null) {
            throw new AppException(AppErrorCodeEnum.YOGA_USER_ID_NULL);
        }
        PrivateVipBO privateVipBO = getPrivateVipByUserId(yogaUserId);
        if (privateVipBO == null) {
            return false;
        }
        if (privateVipBO.getVipStatus() == 0) {
            return false;
        }

        return Boolean.TRUE;
    }
}
